package com.bootdo.system.controller;

import com.bootdo.system.domain.FrontuserDO;
import com.bootdo.system.domain.ZichanhistoryDO;
import com.bootdo.system.service.FrontuserService;
import com.bootdo.system.service.ZichanhistoryService;
import com.bootdo.system.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@ResponseBody
@Controller
public class ZichanController extends  BaseController{

    @Autowired
    private ZichanhistoryService zichanhistoryService;


    @GetMapping("/zichan")
    public R zichanPage(String jiaoyitype,
                        HttpServletRequest request){

        if(StringUtils.isEmpty(jiaoyitype)){
            jiaoyitype =  "0";
        }

        Long userId = getUserId(request);
        //用户资产
         FrontuserDO userDO = getUserDO(request);

        //历史记录
        List<ZichanhistoryDO> zichanhistoryDOS = zichanhistoryService.getUserZichanHistory(userId,jiaoyitype);
        request.setAttribute("zichanhistoryDOS",zichanhistoryDOS);

        return R.ok().put("userDO",userDO).put("zichanhistoryDOS",zichanhistoryDOS);
    }
}
